<?php

/**
 * LayoutBehavior class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Monday, January 30, 2012. 09:21 AM
 */
class LayoutBehavior extends CBehavior {

	public function getMenu() {
		static $menu = null;
		
		if (isset($menu)) {
			return $menu;
		}
		
		$user = Yii::app()->user;
		$userModule = Yii::app()->getModule('user');
		
		$dashboard = array(
			'label'=>'Dashboard',
			'visible'=>!$user->isGuest,
			'items'=>array(
				array(
					'label'=>'PMB',
					'url'=>array('/dashboard/admission'),
				),
				array(
					'label'=>'PMM',
					'items'=>array(
						array(
							'label'=>'Periode',
							'url'=>array('/dashboard/downline/periodic'),
						),
					),
				),
			),
		);
		
		$data = array(
			'label'=>'Data',
			'visible'=>!$user->isGuest,
			'items'=>array(
				array(
					'label'=>'Person',
					'url'=>array('/person/admin'),
				),
				array(
					'label'=>'Konsentrasi',
					'url'=>array('/major/table'),
					'items'=>array(
						array(
							'label'=>'Manage',
							'url'=>array('/major/admin'),
						),
					),
				),
				array(
					'label'=>'Ko-Kurikuler',
					'url'=>array('/curricular/index'),
				),
				array(
					'label'=>'Karyawan',
					'url'=>array('/employee/admin'),
					'items'=>array(
						array(
							'label'=>'Create',
							'url'=>array('/employee/create'),
						),
					),
				),
			),
		);
		
		$registrant = array(
			'label'=>'Pendaftar',
			'url'=>array('/registrant/admin'),
			'visible'=>!$user->isGuest,
			'items'=>array(
				array(
					'label'=>'Formulir',
					'url'=>array('/registrantAdmission/admin'),
					'items'=>array(
						array(
							'label'=>'Laporan',
							'items'=>array(
								array(
									'label'=>'Per Periode',
									'url'=>array(
										'/registrantAdmission/periodicReport'
									),
								),
							),
						)
					),
				),
				array(
					'label'=>'Update Kelulusan',
					'url'=>array('/registrant/graduate'),
				),
				array(
					'label'=>'Laporan',
					'url'=>array('/registrant/report'),
				),
				array(
					'label'=>'Download',
					'items'=>array(
						array(
							'label'=>'Peserta Tes',
							'url'=>array('/registrant/downloadAdmittee'),
						),
						array(
							'label'=>'HP Sudah Regis',
							'url'=>array(
								'/registrant/downloadMessageableStudent'
							),
							
						),
						array(
							'label'=>'Pendidikan',
							'url'=>array(
								'/registrant/downloadEducation'
							),
							
						),
					),
				),
			),
		);

		$student = array(
			'label'=>'Mahasiswa',
			'url'=>array('/student/admin'),
			'visible'=>!$user->isGuest,
			'items'=>array(
				array(
					'label'=>'Semester',
					'items'=>array(
						array(
							'label'=>'Ekspor',
							'url'=>array(
								'/studentTerm/export'
							),
						),
						array(
							'label'=>'Laporan',
							'items'=>array(
								array(
									'label'=>'Sudah Registrasi',
									'url'=>array(
										'/studentTerm/reportRegistered',
									),
								),
							),
						)
					),
				),
				array(
					'label'=>'Konsentrasi',
					'items'=>array(
						array(
							'label'=>'Impor Data Kelas',
							'url'=>array(
								'/studentMajor/import'
							),
						),
						array(
							'label'=>'Laporan',
							'items'=>array(
								array(
									'label'=>'Aktif',
									'url'=>array(
										'/studentMajor/reportActive',
									),
								),
								array(
									'label'=>'Penunggak',
									'url'=>array(
										'/studentMajor/reportDebtor',
									),
								),
								array(
									'label'=>'Belum Registrasi',
									'url'=>array(
										'/studentMajor/reportUnregistered',
									),
								),
							),
						),
						array(
							'label'=>'Tabel',
							'items'=>array(
								array(
									'label'=>'Penunggak',
									'url'=>array(
										'/majorTerm/tableDebtor',
									),
								),
								array(
									'label'=>'Sudah Registrasi',
									'url'=>array(
										'/majorTerm/tableRegistered',
									),
								),
								array(
									'label'=>'Belum Registrasi',
									'url'=>array(
										'/majorTerm/tableUnregistered',
									),
								),
							),
						),
						
					),
				),
			),
		);
		
		$dailyDetail = array(
			'label'=>'Detil',
			'items'=>array(
				array(
					'label'=>'Per Pegawai',
					'url'=>array('/report/dailyUser'),
				),
				array(
					'label'=>'Per Transaksi',
					'url'=>array('/report/dailyTransaction'),
				),
			),
		);
		$report = array(
			'label'=>'Laporan',
			'visible'=>!$user->isGuest,
			'items'=>array(
				array(
					'label'=>'Harian',
					'items'=>array(
						$dailyDetail,
						array(
							'label'=>'Resume',
							'url'=>array('/report/dailyResume'),
						),
					),
				),
				/*
				array(
					'label'=>'PMM',
					'items'=>array(
						array(
							'label'=>'Per Periode',
							'url'=>array('/personDownline/periodicReport'),
						),
						array(
							'label'=>'Detail Per Dosen',
							'url'=>array('/personDownline/detailReport'),
						),
						array(
							'label'=>'Rekap Per Dosen',
							'url'=>array('/personDownline/summaryReport'),
						),
						array(
							'label'=>'Rekap Per Prodi',
							'url'=>array('/personDownline/majorReport'),
						),
					),
				),
				*/
				array(
					'label'=>'Proyek Akhir',
					'items'=>array(
						array(
							'label'=>'Belum Membayar',
							'url'=>array('/studentEssay/unpaidReport'),
						),
						array(
							'label'=>'Sudah Membayar',
							'url'=>array('/studentEssay/paidReport'),
						),
					),
				),
			),
		);
		
		$system = array(
			'label'=>'System',
			'items'=>array(
				array(
					'url'=>$userModule->loginUrl,
					'label'=>$userModule->t("Login"),
					'visible'=>$user->isGuest,
				),
				array(
					'url'=>$userModule->logoutUrl,
					'label'=>$userModule->t("Logout") . " ($user->name)",
					'visible'=>!$user->isGuest,
				),
				array(
					'label'=>'SMS',
					'url'=>array('/message/index'),
					'visible'=>!$user->isGuest,
					'items'=>array(
						array(
							'label'=>'Compose',
							'url'=>array('/message/compose'),
						),
						array(
							'label'=>'Manage',
							'url'=>array('/message/admin'),
						),
						array(
							'label'=>'Laporan',
							'items'=>array(
								array(
									'label'=>'Periode',
									'url'=>array('/message/periodicReport'),
								),
								array(
									'label'=>'Rekapitulasi',
									'url'=>array('/message/summaryReport'),
								),
							),
						),
						array(
							'label'=>'System',
							'items'=>array(
								array(
									'label'=>'Check Voucher',
									'url'=>array('/message/cusd'),
								),
								array(
									'label'=>'Stop Broadcast',
									'url'=>array('/message/stop'),
								),
								array(
									'label'=>'Resume Broadcast',
									'url'=>array('/message/resume'),
								),
							),
						)
					),
				),
				array(
					'label'=>'E-Mail',
					'url'=>array('/mail/admin'),
					'visible'=>!$user->isGuest,
					'items'=>array(
						array(
							'label'=>'Broadcast Honor',
							'url'=>array('/mail/composeHonorarium'),
						),
					),
				),
				array(
					'label'=>'Ticket',
					'visible'=>!$user->isGuest,
					'url'=>array('/ticket/compose'),
					'items'=>array(
						array(
							'label'=>'Open',
							'url'=>array(
								'/ticket/index',
								'status'=>Ticket::STATUS_OPEN,
							),
						),
						array(
							'label'=>'Close',
							'url'=>array(
								'/ticket/index',
								'status'=>Ticket::STATUS_CLOSE,
							),
						),
					),
				),
				array(
					'label'=>'User',
					'url'=>array('/user'),
					'visible'=>!$user->isGuest,
				),
				array(
					'label'=>'Rights',
					'url'=>array('/rights/assignment/view'),
					'visible'=>!$user->isGuest,
				),
				array(
					'label'=>'About',
					'url'=>array('/site/page', 'view'=>'about'),
					'items'=>array(
						array(
							'label'=>'Cecilia',
							'url'=>array('/site/page', 'view'=>'about'),
						),
						array(
							'label'=>'Laura',
							'url'=>array('/laura'),
						),
						array(
							'label'=>'Charlotte',
							'url'=>array('/charlotte'),
						),
					),
				),
			),
		);

		$menu = array(
			array(
				'label'=>'Home',
				'url'=>array('/site/index'),
			),
			$dashboard,
			$data,
			$registrant,
			$student,
			$report,
			$system,
		);

		return $menu;
	}

	private $_assetsUrl;

	public function getAssetsUrl() {
		if ($this->_assetsUrl === null) {
			$path = Yii::getPathOfAlias("application.assets");
			$this->_assetsUrl = Yii::app()->assetManager->publish(
					$path, false, -1, YII_DEBUG
			);
		}
		return $this->_assetsUrl;
	}

}
